package com.ali.juejin.model.main

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.ali.juejin.base.BaseModelView
import com.ali.juejin.bean.home.CategoryBean
import com.ali.juejin.bean.home.FollowBean
import com.ali.juejin.bean.home.followItem.Entrylist
import com.ali.juejin.config.UrlConfig
import com.ali.juejin.services.main.HomeFollowServices
import com.ali.juejin.utils.Request
import com.blankj.utilcode.util.LogUtils

class HomeModel: BaseModelView() {

    val net by lazy { Request.instance(UrlConfig.TIMELINEMERGER) }

    val homeFollowList by lazy { MutableLiveData<ArrayList<Entrylist>>() }
    val homeFollowPage by lazy { MutableLiveData<Float>() }


    fun getHomeRecommendData(){
        request<FollowBean>({
            val data = net.create(HomeFollowServices::class.java).getList("all","month","",20)
            val dataList = data.d.entrylist
            homeFollowList.postValue(data.d.entrylist)
            homeFollowPage.postValue(0f)
//            LogUtils.w(dataList[dataList.size-1].hotIndex)
            homeFollowPage.postValue(dataList[dataList.size-1].hotIndex)
        })
    }

    fun getHomeRecommendMoreData(){
        request<FollowBean>({
            val data = net.create(HomeFollowServices::class.java).getList("all","month",homeFollowPage.value.toString(),20)
            val dataList = data.d.entrylist
            val tempList = homeFollowList.value
            tempList?.addAll(dataList)
            homeFollowList.postValue(tempList)
//            LogUtils.w(dataList[dataList.size-1].hotIndex)
            homeFollowPage.postValue(dataList[dataList.size-1].hotIndex)
        })
    }

}